/**
 * https://ac.nowcoder.com/acm/problem/14602
 */

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int t;
    cin>>t;
    while(t--){
        int n,m;
        cin>>n>>m;
        int v[n+1][1010]={0};
        int w[n+1][1010]={0};
        int dp[m+1]={0};
        vector<int> d(n+1);
        for(int i=1;i<=n;++i){
            int a;
            cin>>a;
            d[i]=a;
            for(int j=1;j<=a;++j){
                cin>>v[i][j];
            }for(int j=1;j<=a;++j){
                cin>>w[i][j];
            }
        }
        for(int i=1;i<=n;++i){
            for(int j=m;j>0;--j){
                for(int k=1;k<=d[i];++k){
                    if(w[i][k]<=j)
                        dp[j]=max(dp[j],v[i][k]+dp[j-w[i][k]]);
                }
            }
        }
        cout<<dp[m]<<endl;
       }
    return 0;
}